package com.example.projectmobile;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.channels.FileChannel;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.os.Environment;
import android.util.Log;

public class MySQLiteHelper extends SQLiteOpenHelper {
	public static final String DATABASE_NAME = "places.db";
	private static final int DATABASE_VERSION = 1;
	public static final String TABLE_PLACE = "Place";
	public static final String COLUMN_ID = "id";
	public static final String COLUMN_NAME = "Name";
	public static final String COLUMN_DESCRIPTION = "Description";
	public static final String COLUMN_LAT = "Lat";
	public static final String COLUMN_LNG = "Long";
	public static final String COLUMN_PIC = "Pic";
	private static final String Place_DATABASE_CREATE = "CREATE TABLE IF NOT EXISTS "
			+ TABLE_PLACE
			+ " ("
			+ COLUMN_ID
			+ " INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE , "
			+ COLUMN_NAME
			+ " TEXT NOT NULL ,"
			+ COLUMN_DESCRIPTION
			+ " TEXT NOT NULL ,"
			+ COLUMN_LAT
			+ " DOUBLE NOT NULL ,"
			+ COLUMN_LNG
			+ " DOUBLE NOT NULL ,"
			+ COLUMN_PIC
			+ " TEXT NOT NULL );";

	private static String DB_PATH = Environment.getExternalStorageState() + "/"
			+ DATABASE_NAME;
	private Context context;

	public MySQLiteHelper(Context context) {
		super(context, DATABASE_NAME, null, DATABASE_VERSION);
		this.context = context;

	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		System.out.println(Place_DATABASE_CREATE);
		db.execSQL(Place_DATABASE_CREATE);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		Log.w(MySQLiteHelper.class.getName(),

		"Upgrading database from version " + oldVersion + " to "

		+ newVersion + ", which will destroy all old data");

		db.execSQL("DROP TABLE IF EXISTS " + TABLE_PLACE);

		onCreate(db);

	}

}